package com.luber.web.controller.backstage;

import java.util.List;

import com.luber.backstage.domain.EticketVehicleModel;
import com.luber.backstage.domain.vo.EticketVehicleModelVO;
import com.luber.backstage.service.IEticketVehicleModelService;
import com.luber.common.core.domain.entity.SysUser;
import com.luber.common.core.domain.model.LoginUser;
import com.luber.common.utils.ServletUtils;
import com.luber.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luber.common.annotation.Log;
import com.luber.common.core.controller.BaseController;
import com.luber.common.core.domain.AjaxResult;
import com.luber.common.enums.BusinessType;
import com.luber.common.utils.poi.ExcelUtil;
import com.luber.common.core.page.TableDataInfo;

/**
 * 【车辆型号】Controller
 *
 * @author luber
 * @date 2021-01-19
 */
@RestController
@RequestMapping("/backstage/vehicleModel")
public class EticketVehicleModelController extends BaseController
{
    @Autowired
    private IEticketVehicleModelService eticketVehicleModelService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询【车辆型号】列表
     */
    @PreAuthorize("@ss.hasPermi('backstage:vehicleModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(EticketVehicleModel eticketVehicleModel)
    {
        startPage();
        List<EticketVehicleModelVO> list = eticketVehicleModelService.selectEticketVehicleModelList(eticketVehicleModel);
        return getDataTable(list);
    }

    /**
     * 导出【车辆型号】列表
     */
    @PreAuthorize("@ss.hasPermi('backstage:vehicleModel:export')")
    @Log(title = "【车辆型号】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EticketVehicleModel eticketVehicleModel)
    {
        List<EticketVehicleModelVO> list = eticketVehicleModelService.selectEticketVehicleModelList(eticketVehicleModel);
        ExcelUtil<EticketVehicleModelVO> util = new ExcelUtil<EticketVehicleModelVO>(EticketVehicleModelVO.class);
        return util.exportExcel(list, "vehicleModel");
    }

    /**
     * 获取【车辆型号】详细信息
     */
    @PreAuthorize("@ss.hasPermi('backstage:vehicleModel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eticketVehicleModelService.selectEticketVehicleModelById(id));
    }

    /**
     * 新增【车辆型号】
     */
    @PreAuthorize("@ss.hasPermi('backstage:vehicleModel:add')")
    @Log(title = "【车辆型号】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EticketVehicleModel eticketVehicleModel)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        // 用户信息
        SysUser user = loginUser.getUser();
        eticketVehicleModel.setCreateUser(user.getUserId());
        return toAjax(eticketVehicleModelService.insertEticketVehicleModel(eticketVehicleModel));
    }

    /**
     * 修改【车辆型号】
     */
    @PreAuthorize("@ss.hasPermi('backstage:vehicleModel:edit')")
    @Log(title = "【车辆型号】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EticketVehicleModel eticketVehicleModel)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        // 用户信息
        SysUser user = loginUser.getUser();
        eticketVehicleModel.setUpdateUser(user.getUserId());
        return toAjax(eticketVehicleModelService.updateEticketVehicleModel(eticketVehicleModel));
    }

    /**
     * 删除【车辆型号】
     */
    @PreAuthorize("@ss.hasPermi('backstage:vehicleModel:remove')")
    @Log(title = "【车辆型号】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eticketVehicleModelService.deleteEticketVehicleModelByIds(ids));
    }
}
